import EventEmitter from "events";

class EventController extends EventEmitter {
    public moduleNum:number = 6; //模块的数量
    public settingData:Array<Array<Record<string,string | number>>> = []
    public initModuleList(moduleNum: number) {
        for(let i=0;i<this.moduleNum;i++) {
            this.settingData.push([
            {
                id: 1,
                name: "message.uv",
                normal_low: 100,
                normal_high: 5000,
                current_val: 1300,
            },
            {
                id: 2,
                name: "message.inf",
                normal_low: -40,
                normal_high: 150,
                current_val: 100
            },
            {
                id: 3,
                name: "message.tem",
                normal_low: -40,
                normal_high: 80,
                current_val: 30
            },
            {
                id: 5,
                name: "message.hum",
                normal_low: 0,
                normal_high: 90,
                current_val: 45
            },
            {
                id: 6,
                name: "message.pre",
                normal_low: 0,
                normal_high: 200,
                current_val: 121
            }
         ])
        }
    }
    // 初始化模块的个数
    public initConfig(moduleNum: number) {
        if (isNaN(moduleNum) && this.moduleNum > 10) {
            console.log("设置配置成功" + moduleNum)
            this.moduleNum = 10
            this.initModuleList(this.moduleNum)
        } else {
            this.moduleNum = moduleNum
            this.initModuleList(this.moduleNum)
        }
    
    }
    // 修改阈值
    changeVal(id,type,val) {
        try {
            this.settingData[id - 1][type].current_val = val // 设置报警阈值
        } catch (error) {
            console.log(error)
        }
    }

}
   const eventEmit = new EventController()

export default eventEmit
